/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.malva.dbpop;

import java.security.SecureRandom;

/**
 *
 * @author vramirez
 */
public class RandomNum extends AbstractDBPopType {

    private Integer init;
    private Integer end;
    private SecureRandom secur;
    private Integer length;

    public RandomNum() {
        this.secur = new SecureRandom();
    }

    public RandomNum(Integer init, Integer end) {
        this();
        if (this.init > this.end) {
            throw new IllegalArgumentException("end parameter must be greater than init");
        }
        this.init = init;
        this.end = end;
        this.length = end - init;
    }

    public String next() {
        if (length == null) {
            return "" + secur.nextInt();
        } else {
            return "" + (init + secur.nextInt(length + 1));
        }
    }
}
